{{- $oe := .Site.Params.oembed -}}
{{ $host := .Get 0 }}
{{- if not $oe.privacy -}}
{{- if or (eq $host "ig") (eq $host "fb") -}}
{{- $accessToken := getenv "HUGO_OEMBED_ACCESSTOKEN" | default $oe.facebook.accessToken -}}
  {{- if not $accessToken -}}
    {{- erroridf "err-missing-oembed-accesstoken" "oembed shortcode: Missing config value for .Site.Params.oembed.accessToken. This can be set in config.toml, but it is recommended to configure this via the HUGO_OEMBED_ACCESSTOKEN OS environment variable. If you are using a Client Access Token, remember that you must combine it with your App ID using a pipe symbol (<APPID>|<CLIENTTOKEN>) otherwise the request will fail." -}}
  {{- else -}}
    {{ $type := .Get 1 }}
    {{ $id := .Get 2 }}
    {{- if eq $host "ig" -}}
      {{ $hideCaption := cond (eq (.Get 3) "hidecaption") "1" "0" }}
      {{ with getJSON "https://graph.facebook.com/v11.0/instagram_oembed/?url=https://instagram.com/" $type "/" $id "/&hidecaption=" $hideCaption "&access_token=" $accessToken }}
        {{ .html | safeHTML }}
      {{ end }}
    {{- else if eq $host "fb" -}}
      {{- if eq $type "page" -}}
        {{ with getJSON "https://graph.facebook.com/v11.0/oembed_" $type "?url=" $id "&show_posts=false" "&access_token=" $accessToken }}
          {{ .html | safeHTML }}
        {{ end }}
      {{- else -}}
        {{ with getJSON "https://graph.facebook.com/v11.0/oembed_" $type "?url=" $id "&access_token=" $accessToken }}
          {{ .html | safeHTML }}
        {{ end }}
      {{- end -}}
    {{- end -}}
  {{- end -}}
{{- else if (eq $host "tweet") -}}
  {{ $url := .Get 1 }}
  {{- $dnt := $oe.twitter.enableDNT | default false -}}
  {{ with getJSON "https://publish.twitter.com/oembed" "?url=" $url "&dnt=" $dnt }}
    {{ .html | safeHTML }}
  {{ end }}
{{- end -}}
{{- end -}}
